package org.mch.func.m_px.sorteg;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JSplitPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.LineBorder;

import org.mch.biz.ui.FuncEvent;
import org.mch.biz.ui.FuncPanel;
import org.mch.swingm.core.MToggleButton;

public class SortPanel extends FuncPanel {
	private static final long serialVersionUID = 7436929897080596483L;
	private JSplitPane splitPane;
	private JPanel panel;
	private JPanel panelDown;
	private JSplitPane splitPane_1;
	private JPanel panelUp;
	private JPanel panel_3;
	private JScrollPane scrollPane;
	private JPanel panel_4;
	private JButton btnCreateBtnArry;
	private JButton btnExchange;

	private MToggleButton[] btnSorts;
	private JSlider sliderMoveSpeed;
	private JLabel labelUp;
	private JLabel labelDown;

	public SortPanel() {
		super();
		setLayout(new BorderLayout(0, 0));
		add(getSplitPane(), BorderLayout.CENTER);
	}

	@Override
	protected FuncEvent createEvent() {
		return new SortEvent(this);
	}

	public JSplitPane getSplitPane() {
		if (splitPane == null) {
			splitPane = new JSplitPane();
			splitPane.setResizeWeight(0.6);
			splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
			splitPane.setLeftComponent(getPanel());
			splitPane.setRightComponent(getPanelDown());
			splitPane.setDividerLocation(0.6);
		}
		return splitPane;
	}

	public JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getSplitPane_1(), BorderLayout.CENTER);
		}
		return panel;
	}

	public JPanel getPanelDown() {
		if (panelDown == null) {
			panelDown = new JPanel();
			panelDown.setLayout(null);
		}
		return panelDown;
	}

	public JSplitPane getSplitPane_1() {
		if (splitPane_1 == null) {
			splitPane_1 = new JSplitPane();
			splitPane_1.setResizeWeight(0.8);
			splitPane_1.setOrientation(JSplitPane.VERTICAL_SPLIT);
			splitPane_1.setLeftComponent(getPanelUp());
			splitPane_1.setRightComponent(getPanel_3());
			splitPane_1.setDividerLocation(0.8);
		}
		return splitPane_1;
	}

	public JPanel getPanelUp() {
		if (panelUp == null) {
			panelUp = new JPanel();
			panelUp.setLayout(null);
			panelUp.add(getLabelUp());
			panelUp.add(getLabelDown());
		}
		return panelUp;
	}

	public JPanel getPanel_3() {
		if (panel_3 == null) {
			panel_3 = new JPanel();
			panel_3.setLayout(new BorderLayout(0, 0));
			panel_3.add(getScrollPane(), BorderLayout.CENTER);
		}
		return panel_3;
	}

	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
			scrollPane.setViewportView(getPanel_4());
		}
		return scrollPane;
	}

	public JPanel getPanel_4() {
		if (panel_4 == null) {
			panel_4 = new JPanel();
			panel_4.setLayout(new FlowLayout(FlowLayout.LEFT));
			panel_4.add(getBtnCreateBtnArry());
			panel_4.add(getBtnExchange());
			panel_4.add(getSliderMoveSpeed());
		}
		return panel_4;
	}

	public JButton getBtnCreateBtnArry() {
		if (btnCreateBtnArry == null) {
			btnCreateBtnArry = new JButton("重构新数组");
			btnCreateBtnArry.setFont(new Font("宋体", Font.PLAIN, 12));
			btnCreateBtnArry.addActionListener(getEvent());
		}
		return btnCreateBtnArry;
	}

	public JButton getBtnExchange() {
		if (btnExchange == null) {
			btnExchange = new JButton("交换");
			btnExchange.setFont(new Font("宋体", Font.PLAIN, 12));
			btnExchange.addActionListener(getEvent());
		}
		return btnExchange;
	}

	public MToggleButton[] getBtnSorts() {
		return btnSorts;
	}

	public void setBtnSorts(MToggleButton[] btnSorts) {
		this.btnSorts = btnSorts;
	}

	public JSlider getSliderMoveSpeed() {
		if (sliderMoveSpeed == null) {
			sliderMoveSpeed = new JSlider();
			sliderMoveSpeed.setValue(5);
			sliderMoveSpeed.setMaximum(50);
			sliderMoveSpeed.setMinimum(1);
		}
		return sliderMoveSpeed;
	}

	public JLabel getLabelUp() {
		if (labelUp == null) {
			labelUp = new JLabel("");
			labelUp.setBorder(new LineBorder(Color.BLUE));
			labelUp.setBounds(0, 10, 2000, 2);
		}
		return labelUp;
	}

	public JLabel getLabelDown() {
		if (labelDown == null) {
			labelDown = new JLabel("");
			labelDown.setBorder(new LineBorder(Color.BLUE));
			labelDown.setBounds(0, 82, 2000, 2);
		}
		return labelDown;
	}
}
